package cn.funeralobjects.aoss.service;

import cn.funeralobjects.ams.web.api.ProductApi;
import cn.funeralobjects.ams.web.api.ProductApiApi;
import cn.funeralobjects.ams.web.service.BaseAliyunMouduleRegister;
import cn.funeralobjects.utils.aliyun.core.model.AliyunAction;
import cn.funeralobjects.utils.aliyun.core.model.AliyunProduct;
import cn.funeralobjects.utils.aliyun.oss.OssAction;
import cn.funeralobjects.utils.aliyun.oss.OssProduct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

/**
 * @author FuneralObjects
 * Create date: 2020/6/1 7:41 PM
 */
@Component
public class AliyunOssModuleRegister extends BaseAliyunMouduleRegister {

    @Resource
    private ProductApi productApi;
    @Resource
    private ProductApiApi productApiApi;

    private static final List<AliyunProduct> ALIYUN_PRODUCT_LIST = List.of(OssProduct.PRODUCT);

    private static final ConcurrentMap<String, List<AliyunAction>> PRODUCT_ALIYUN_ACTION_MAP = ALIYUN_PRODUCT_LIST.stream().collect(Collectors.toConcurrentMap(AliyunProduct::code, prod -> List.of(OssAction.ALL)));

    private static final Logger LOGGER = LoggerFactory.getLogger(AliyunOssModuleRegister.class);

    @Override
    protected ProductApi getProductApi() {
        return productApi;
    }

    @Override
    protected ProductApiApi getProductApiApi() {
        return productApiApi;
    }

    @Override
    protected List<AliyunProduct> getRegisteredProducts() {
        return ALIYUN_PRODUCT_LIST;
    }

    @Override
    protected ConcurrentMap<String, List<AliyunAction>> getRegisteredProductApis() {
        return PRODUCT_ALIYUN_ACTION_MAP;
    }

    @Override
    protected Logger getLogger() {
        return LOGGER;
    }
}
